(function() {
  var DATE_EXPRESSION, DATE_FORMAT, Task, TomatoBreak;
  var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
    for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
    function ctor() { this.constructor = child; }
    ctor.prototype = parent.prototype;
    child.prototype = new ctor;
    child.__super__ = parent.prototype;
    return child;
  };
  TomatoBreak = this.TomatoBreak;
  TomatoBreak.DATE_FORMAT = DATE_FORMAT = 'yyyy-MM-dd';
  DATE_EXPRESSION = /^\d{4}[-]\d{2}[-]\d{2}$/;
  Task = (function() {
    __extends(Task, Spine.Model);
    function Task() {
      Task.__super__.constructor.apply(this, arguments);
    }
    Task.configure('Task', 'name', 'planned', 'notes', 'estimation', 'createdAt', 'dueAt', 'completedAt');
    Task.extend(Spine.Model.Ajax);
    Task.prototype.createdAt = Date.today().toString(DATE_FORMAT);
    Task.prototype.planned = true;
    Task.prototype.validate = function() {
      var addError, errors, estimation;
      errors = [];
      addError = function(name, message) {
        var error;
        error = {
          name: name,
          messages: []
        };
        error.messages.push(message);
        return errors.push(error);
      };
      if (!this.name) {
        addError('name', 'Name cannot be blank.');
      }
      if (this.estimation) {
        estimation = parseInt(this.estimation, 10);
        if ((isNaN(estimation)) || estimation < 1) {
          addError('estimation', 'Estimation must be a positive integer.');
        }
      }
      if (this.dueAt) {
        if (DATE_EXPRESSION.test(this.dueAt)) {
          if (((Date.parse(this.dueAt, DATE_FORMAT)).compareTo(Date.today())) < 0) {
            addError('dueAt', 'Due date cannot be in past date.');
          }
        } else {
          addError('dueAt', 'Unable to recognize the date format.');
        }
      }
      if (errors.length) {
        return errors;
      }
    };
    return Task;
  })();
  TomatoBreak.Task = Task;
}).call(this);
